/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package GenerateDB;

import JDBC.UtilsJDBC;
import com.google.gson.Gson;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *
 * @author escabia
 */
public class ScriptMongo extends Script
{
    private ArrayList<ArrayList<HashMap<String,Object> > > objetos;
    private ArrayList<String> nomsCollection = new ArrayList<>();
    
    
    public ScriptMongo(){
        objetos = new ArrayList<>();
        
        UtilsJDBC selectsmongo = new UtilsJDBC();
        
        /** Consultas Mongo **/
        objetos.add(selectsmongo.entidadesaisladas());
        nomsCollection.add("entidadesaisladas");
        objetos.add(selectsmongo.entdebilrelident());
        nomsCollection.add("entdebilrelident");
        objetos.add(selectsmongo.reflexivas());
        nomsCollection.add("reflexivas");
        objetos.add(selectsmongo.ternarias());
        nomsCollection.add("ternarias");
        objetos.add(selectsmongo.entidadpornumrel());
        nomsCollection.add("entidadpornumrel");
        
        
        selectsmongo.disconnect();
    }    
    
    
    /**
     * @param esquema
     * @param ruta 
     */
    public void generate(String ruta){
        Gson gson = new Gson();
       
        try 
        {
            this.script = new PrintWriter(ruta);
            for(int i=0; i<objetos.size(); i++)
            {  
                this.script.println("db." + nomsCollection.get(i) + ".insert(" );
                this.script.println(gson.toJson(objetos.get(i)));
                this.script.println(")");
                
            }    
            this.script.flush();
        } 
        catch (FileNotFoundException ex) {
            Logger.getLogger(ScriptSQL.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.script.close();
    }    
}
